USE [DemoDB]
GO

/****** Object:  StoredProcedure [dbo].[Resourse_Graphic_Assignment]    Script Date: 09/20/2012 23:29:50 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Rosario Silva
-- Create date: 20/09/2012
-- Description:	Obtiene el numero de Recursos 
--              Asignados y Libres
-- =============================================
CREATE PROCEDURE [dbo].[Resourse_Graphic_Assignment]	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
    SELECT
    (SELECT COUNT (R.Id) 
	FROM   Recurso R 
		   INNER JOIN LineaTiempo LT
	               ON R.id = LT.recursoId
	WHERE  GETDATE() BETWEEN LT.fechaInicio AND LT.fechaFinal
	  AND  R.Activo = 1) asignados,

	(SELECT COUNT (R.Id) 
    FROM   Recurso R 
	       LEFT JOIN LineaTiempo LT
                  ON R.id = LT.recursoId
    WHERE  GETDATE() NOT BETWEEN LT.fechaInicio AND LT.fechaFinal
      AND  R.Activo = 1) libres
    
    SET NOCOUNT OFF;
END
GO
